package com.blb.community.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blb.community.mapper.ZyOwnerMapper;
import com.blb.community.pojo.ZyOwner;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Resource
    private ZyOwnerMapper zyOwnerMapper;




    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException{
        ZyOwner user = zyOwnerMapper.selectOne(new QueryWrapper<ZyOwner>().eq("owner_phone_number", s));
        if(user==null){
            throw new UsernameNotFoundException("业主不存在");
        }
        return new org.springframework.security.core.userdetails.User(
                user.getOwnerPhoneNumber(),
                user.getOwnerPassword(),
                new ArrayList<GrantedAuthority>()
        );
    }
}
